package android.slc.app;

import android.slc.app.shutdown.ShutdownManager;
import android.slc.app.startup.TaskConstant;
import android.slc.app.startup.TaskUtils;
import android.slc.appbase.ui.AppStageLauncherConfigSimple;
import android.slc.box.anchors.AnchorsManager;
import android.slc.box.anchors.task.Task;
import android.slc.box.commonlibrary.compat.SlcResourceUtils;
import android.slc.box.core.launcher.StageLauncher;
import android.slc.box.core.launcher.StageLauncherBuilder;
import android.slc.box.guice.MvvmfxGuiceApplication;
import android.slc.module.sys.ui.welcome.WelcomeView;
import javafx.application.Application;
import javafx.stage.Stage;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;

public class App extends MvvmfxGuiceApplication {

    public static void main(String... args) {
        Locale.setDefault(Locale.CHINESE);
        launch(args);
    }

    @Override
    public void initMvvmfx() throws Exception {
        super.initMvvmfx();
    }

    @Override
    public void startMvvmfx(Stage stage) {
        Application.setUserAgentStylesheet("/atlantafx/primer-light.css");
        AnchorsManager.getInstance().debuggable(true).start(TaskUtils.getAppTaskBuilder().add(new Task("launcherWindow", false) {
            @Override
            protected void run(@NotNull String name) {
                stage.setTitle(SlcResourceUtils.getString("app_name"));
                StageLauncher stageLauncher = StageLauncherBuilder.newBuilder().setStylesheets("/style/app.css", "/style/project.css").build();
                stageLauncher.launcherWindow(stage, WelcomeView.class, AppStageLauncherConfigSimple.Companion.newInstance());
            }
        }).dependOn(TaskConstant.TASK_FIRST).build());
    }

    @Override
    public void stopMvvmfx() {
        ShutdownManager.shutdown();
    }
}
